local Widget = GLOBAL.require('widgets/widget')
-- ac = GLOBAL.require("components/hounded")
local ATTACK_WARNING = GetModConfigData("ATTACK_WARNING")

-- A full Day lasts for 8 real-time minutes
local secADay = 8 * 60
local function second2Day(val) 
	return (math.floor(val*10 / secADay)/10)--变换为1位小数
end

local function AttackWarning(inst)
	inst:ListenForEvent("cycleschanged",function(inst)
		if GLOBAL.TheWorld.ismastersim then
			if GLOBAL.TheWorld.components.hounded then
				local data = GLOBAL.TheWorld.components.hounded:GetTimeToAttack()
				if GLOBAL.TheWorld:HasTag("cave") then
					GLOBAL.TheNet:Announce("深渊蠕虫的攻击还有"..second2Day(data).."天到来！")
				else 
					GLOBAL.TheNet:Announce("猎犬的攻击还有"..second2Day(data).."天到来！")
				end
			end
			if GLOBAL.TheWorld.components.deerclopsspawner and GLOBAL.TheWorld.state.season == "winter" then
				local data,ents=GLOBAL.TheWorld.components.deerclopsspawner:OnSave()
				if data and data.timetoattack then
					print(data.timetoattack)
					GLOBAL.TheNet:Announce("独眼巨鹿的攻击还有"..second2Day(data.timetoattack).."天到来！")
				end
			end
			if GLOBAL.TheWorld.components.beargerspawner and GLOBAL.TheWorld.state.isautumn == true then
				local data,ents=GLOBAL.TheWorld.components.beargerspawner:OnSave()
				if data and data.timetospawn then
					print(data.timetospawn)
					GLOBAL.TheNet:Announce("大熊的攻击还有"..second2Day(data.timetospawn).."天到来！")
				end
			end
		end
		end,GLOBAL.TheWorld)

end

--隐藏值，只能通过带self的函数读取，此方法不行
-- local function AddTimePrompt(self,inst)
	-- function self:GetTimeToAttacktest()
		-- return _timetoattack
	-- end

-- end

if ATTACK_WARNING then
	-- AddComponentPostInit("deerclopsspawner",AddTimePrompt)
	AddPrefabPostInit("world", AttackWarning)
end

